package com.cskaoyan.controller.wxcontroller;

import java.util.Arrays;
import java.util.HashMap;

/**
 * @Author Gan
 * @Date 2021/8/13 11:54
 * @Description: 统计数组中每个数的个数 用HashMap
 */
public class MyTest3 {
    public static void main(String[] args) {

    }

    public static void countNum(int[] nums) {
        HashMap<Character, Integer> map = new HashMap<>();
        String str = Arrays.toString(nums);
        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            //获得主键的value value存放字符出现个数
            Integer count = map.get(ch);
            if (count == null) {
                map.put(ch, 1);
            } else {
                map.put(ch, count + 1);
            }
            System.out.println(map);

        }

    }

    public static void count(int[] nums) {
        HashMap<Character, Integer> map = new HashMap<>();
        String str = Arrays.toString(nums);
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            map.merge(c, 1, (a, b) -> a + b);
        }
    }
}
